package com.vitabuybuy.tv.dialog

import android.content.Context
import android.view.View
import android.view.animation.Animation
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.PopupAllLimitedGroupBinding
import com.vitabuybuy.tv.databinding.PopupRechargePayBinding
import com.vitabuybuy.tv.ui.cart.OrderPayActivity
import kotlinx.android.synthetic.main.activity_order_pay.*
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.TranslationConfig

/**
 * 充值弹出框
 */
class RechargePopup(
    context: Context,
    val onComfir: (payMethon: String) -> Unit
) : BasePopupWindow(context) {

    private lateinit var mBinding: PopupRechargePayBinding

    private val PAY_BY_WECHAT = "微信"
    private val PAY_BY_ALIPAY = "支付宝"
    private val PAY_BY_BANK = "银联"
    private var paymentMethod = PAY_BY_WECHAT
    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_recharge_pay)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        mBinding = DataBindingUtil.bind<ViewDataBinding>(contentView) as PopupRechargePayBinding

        mBinding.rgChoosePay.setOnCheckedChangeListener { _, checkedId ->
            when (checkedId) {
                R.id.rb_wechat_pay -> paymentMethod = PAY_BY_WECHAT
                R.id.rb_ali_pay -> paymentMethod = PAY_BY_ALIPAY
                R.id.rb_bank -> paymentMethod = PAY_BY_BANK
            }
        }

        mBinding.btnPay.setOnClickListener {
            onComfir.invoke(paymentMethod)
            dismiss()
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.FROM_BOTTOM)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.TO_BOTTOM)
            .toDismiss()
    }
}